<?php

class Route extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'route':
	 * @var string $mnemonic
	 * @var string $label
	 * @var string $description
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'route';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('mnemonic','length','max'=>5),
			array('label','length','max'=>100),
			array('mnemonic, label, active', 'required'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'steps' => array(self::MANY_MANY, 'Step', 'route_step(route_mnemonic, step_id)', 'order' => 'orderIndex asc', 'condition' => 'active = 1'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'mnemonic' => 'Mnemonic',
			'label' => 'Label',
			'description' => 'Description',
			'active' => 'Active',
		);
	}
	
	public function primaryKey()
	{
	    return 'mnemonic';
	}
	
}